package timex

import (
	"errors"
	"fmt"
	"time"
)

const (
	UnderLineTimeFormat = "20060102_150405"
	MidLineTimeFormat   = "2006-01-02 15:04:05"
)

func FormatStandardTime(time time.Time) string {
	return time.Format("2006-01-02 15:04:05")
}

// StringTimeFormat 字符串时间格式化
// value: 待格式化数据, format:格式化格式, local:格式化时区
func StringTimeFormat(value, format string, local *time.Location) (time.Time, error) {
	timeVal, err := time.ParseInLocation(format, value, local)
	if err != nil {
		return time.Now(), errors.New(fmt.Sprintf("param:%s format invalid, should like %s", value, format))
	}
	return timeVal, nil
}
